package com.showsu.editor.manage;

import com.showsu.editor.entity.dto.ShuXiuCommonDTO;
import com.showsu.editor.enums.ResultCode;
import com.showsu.editor.utils.aliyun.moderaction.*;
import com.showsu.editor.utils.baidu.AipOcrHandle;
import com.showsu.editor.enums.ModerationRiskLevelEnum;
import com.showsu.editor.utils.remote.ShuXiuUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.LinkedList;
import java.util.List;

/**
 * todo
 *
 * @author jph
 *  * @since 2024/9/19
 */
@Component
@Slf4j
public class XhsEditorAwemeBusinessManager {
    @Autowired
    private AliyunTextModerationUtil aliyunTextModerationUtil;

    @Autowired
    private AliyunImageModerationUtil aliyunImageModerationUtil;

    @Autowired
    private AipOcrHandle aipOcrHandle;

    @Autowired
    private ShuXiuUtils shuXiuUtils;

    @Value("${datashows.awemePreview.url}")
    private String awemePreviewUrl;

    public String getAwemePreviewUrl() {
        return awemePreviewUrl;
    }

    public ModerationRiskLevelEnum imageModeration(String imageUrl){
        AliyunModerationRiskLevelEnum riskLevelEnum=aliyunImageModerationUtil.startGetRiskLevel(AliyunImageModerationServiceCodeEnum.baselineCheck_pro,imageUrl);
        switch (riskLevelEnum){
            case high:
                return ModerationRiskLevelEnum.high;
            case medium:
                return ModerationRiskLevelEnum.medium;
            case low:
                return ModerationRiskLevelEnum.low;
            case none:
                return ModerationRiskLevelEnum.none;
            default:
                return ModerationRiskLevelEnum.unknown;
        }
    }

    public ModerationRiskLevelEnum textModeration(String content){
        AliyunModerationRiskLevelEnum riskLevelEnum=aliyunTextModerationUtil.PlusStartGetRiskLevel(AliyunTextModerationPlusServiceCodeEnum.comment_detection_pro,content);
        switch (riskLevelEnum){
            case high:
                return ModerationRiskLevelEnum.high;
            case medium:
                return ModerationRiskLevelEnum.medium;
            case low:
                return ModerationRiskLevelEnum.low;
            case none:
                return ModerationRiskLevelEnum.none;
            default:
                return ModerationRiskLevelEnum.unknown;
        }
    }

    public ModerationRiskLevelEnum wxTextModeration(String content){
        ModerationRiskLevelEnum riskLevelEnum=shuXiuUtils.wxMaSecCheck(2,content);
        if(ModerationRiskLevelEnum.high.equals(riskLevelEnum)
                ||ModerationRiskLevelEnum.medium.equals(riskLevelEnum)
        ){
            return riskLevelEnum;
        }
        ModerationRiskLevelEnum thislevel=shuXiuUtils.wxMaSecCheck(3,content);
        if(thislevel.getLevel()> riskLevelEnum.getLevel()){
            return thislevel;
        }
        return riskLevelEnum;
    }

    /**
     * 小红书文字识别功能
     * @param imgUrl
     * @return
     */
    public List<String> ocr(String imgUrl) {
        List<String> result=new LinkedList<String>();
        result=aipOcrHandle.basicAccurateGeneral(imgUrl);
        return result;
    }

    public String xhsAgoraSignature(){
        ShuXiuCommonDTO res=shuXiuUtils.xhsAgoraSignature();
        if(res==null){
            return null;
        }
        if(res.getCode().equals(String.valueOf(ResultCode.SUCCESS.getCode()))){
            return res.getData();
        }
        return "";
    }

}
